  <!-- Right side column. Contains the navbar and content of the page -->
            <aside class="right-side">                
                <!-- Content Header (Page header) -->
                <section class="content-header">
                    <h1>
                        ÉQUIPES Viabilis
                        <small>Control panel</small>
                    </h1>
                    <ol class="breadcrumb">
                        <li><a href="<?=site_url()?>"><i class="fa fa-dashboard"></i> Accueil</a></li>
                        <li >Configurations</li>
                        <li class="active">Équipes Viabilis</li>
                    </ol>
                </section>

                <!-- Main content -->
                <section class="content">
                     <div class="row ">
                       <div class="col-xs-12">
                                <a class="btn btn-app" href="<?=site_url()?>users/addUser"><i class="fa fa-plus-circle"> </i>Nouveau Staff</a>
                        </div>
                    
                        <div class="col-xs-12">
                            <div class="box">
                   
                                <div class="box-body table-responsive no-padding">
                                    <table class="table table-hover">
                                        <tr>
                                            <th></th>
                                            <th>Name</th>
                                            <th>Email</th>                                            
                                            <th>Téléphone</th>
                                            <th>Adresse</th>
                                            <th>Authorisation</th>
                                            <th>Dernière Activité</th>
                                          	<th>Status</th>
                                          	<th>limite de tentative</th>
                                            <th>Actions</th>
                                        </tr>
                                        <?php foreach ($userList as $u):?>
                                    	<tr id="user_<?=$u->id?>">
                                    		<?php $groups = $this->aauth->get_user_groups($u->id);?>
                                    		<td class="text-center">	<?php if($u->avatar){?>
                					<img class="img-circle " src="<?=base_url()?>uploads/avatar/thumbs/<?=$u->avatar?>" width="25" height="25">
                					<?php }else{?>
                					<img class="img-circle " src="<?=base_url()?>uploads/avatar/medium/avatar_default.png" width="25">
                					<?php }?></td>
                                    		<td class="allowEdit"><a href="#" id="name"  data-type="text" data-pk="<?=$u->id?>" data-url="<?=site_url()?>users/modification" data-title="Nom"><?=$u->name?></a></td>
                                    		<td class="allowEdit"><a href="#" id="email"  data-type="text" data-pk="<?=$u->id?>" data-url="<?=site_url()?>users/modification" data-title="email"><?=$u->email?></a></td>
                                    		<td class="allowEdit"><a href="#" id="telephone"  data-type="text" data-pk="<?=$u->id?>" data-url="<?=site_url()?>users/modification" data-title="telephone"><?=$u->telephone?></a></td>
                                    		<td class="allowEdit"><a href="#" id="address"  data-type="text" data-pk="<?=$u->id?>" data-url="<?=site_url()?>users/modification" data-title="adresse"><?=$u->address?></a></td>
                                    		<td class="allowEdit"><a href="#" id="<?php foreach ($groups as $g):?><?=$g->id?><?php endforeach;?>" data-type="select" data-pk="<?=$u->id?>" data-value="<?php foreach ($groups as $g):?><?=$g->id?><?php endforeach;?>" data-url="<?=site_url()?>users/modification" data-source="<?=site_url()?>users/selectData/group" title="Titre"><small class="badge bg-green"><?php foreach ($groups as $g):?><?=$g->name?><?php endforeach;?></small></a></td>
                                    		<td><?php if($u->last_activity){echo $u->last_activity;}else{?>--:--:--<?php }?></td>
                                    		<td class="status_<?=$u->id?>"><?php if( $u->banned == 0 && $u->verification_code =='' ){?><span class="label label-success">activé</span><?php }elseif($u->banned == 0 && $u->verification_code !=''){?><span class="label label-warning">en attendant</span><?php }elseif ($u->banned == 1 ){?><span class="label label-danger">suspendu</span><?php }?></td>
                                    		<td><span class="badge <?php if($u->login_attempts<7){?>bg-green<?php }elseif($u->login_attempts >= 7 && $u->login_attempts < 10){?>bg-yellow<?php }else{?>bg-maroon<?php }?>"> <?=$u->login_attempts?> <i class="fa <?php if($u->login_attempts<7){?>fa-check<?php }elseif($u->login_attempts >= 7 && $u->login_attempts < 10){?>fa-warning<?php }else{?>fa-times<?php }?>"></i></span><?php if($u->login_attempts >=10){?> | <form role="form" class="inline" action="<?=site_url()?>users/reset_login_attempt" method="post"><input type="hidden" name="user_id" value="<?=$u->id?>"><button type="submit" class="btn btn-xs bg-green"><i class="fa fa-unlock"></i></button></form><?php }?></td>
                                    		<td>
                                    		<div class="btn-group btn-group-sm ">
                                    			<button class="btn  btn-default <?php if($u->id == $user->id){?>disabled<?php }?>" type="button" onclick="resetPass('<?=$u->id?>','<?=$u->name?>')"><i class="fa fa-key"></i></button>
                                    			<?php if($this->aauth->is_banned($u->id)){?>
                                    			<button class="btn btn-default bannedUser_<?=$u->id?> <?php if($u->id == $user->id){?>disabled<?php }?>" type="button"  onclick = "unbanUser('<?=$u->id?>','<?=$u->name?>')"><i class="fa fa-check-circle"></i></button>
                                    			<?php }else{?>
                                    			<button class="btn btn-default bannedUser_<?=$u->id?> <?php if($u->id == $user->id){?>disabled<?php }?>" type="button"  onclick = "bannedUser('<?=$u->id?>','<?=$u->name?>')"><i class="fa fa-minus-circle"></i></button>
                                    			<?php }?>
                                    			<button class="btn  btn-default <?php if($u->id == $user->id){?>disabled<?php }?>" type="button" onclick="deleteUser('<?=$u->id?>','<?=$u->name?>')"><i class="fa fa-trash-o"></i></button>
                                    		</div>
                                    		</td>
                                    		
                                    	</tr>
                                    	<?php endforeach;?>
                                    </table>
                                </div><!-- /.box-body -->
                            </div><!-- /.box -->
                     
                    </div>

                            </div>
                           
                </section><!-- /.content -->
            </aside><!-- /.right-side -->
        </div><!-- ./wrapper -->
        <!-- Button trigger modal -->

<!-- Modal -->
<div class="modal fade" id="banned" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
        <h4 class="modal-title" id="myModalLabel">Modal title</h4>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
       
       
      </div>
    </div>
  </div>
</div>
        <!-- Modal -->
<div class="modal fade" id="unban" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
        <h4 class="modal-title" id="myModalLabel">Modal title</h4>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
       
       
      </div>
    </div>
  </div>
</div>
 <!-- Modal -->
<div class="modal fade" id="deleteUser" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
        <h4 class="modal-title" id="myModalLabel">Modal title</h4>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
       
       
      </div>
    </div>
  </div>
</div>
<!-- Modal -->
<div class="modal fade" id="resetPass" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
        <h4 class="modal-title" id="myModalLabel">Modal title</h4>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
       
       
      </div>
    </div>
  </div>
</div>
         <script>
        
        	$(function(){
            		/* initilize x-editable on dd a */
        		    			
					$(' td.allowEdit a').editable({
						mode:'inline',				
						emptytext:'- vide -',		
						success:function(response, newValue){
							if(response !='email' ){
								location.reload();
							}
						}
					})

            	});

            function bannedUser($id,$name){
              var $data = "'"+$id+"','"+$name+"'";
            
            	$('#banned').modal({
            		  keyboard: false
            		});
                		$("#banned .modal-title").html('Suspendre cet utilisateur');
                		$("#banned .modal-body").html('<b>Compte: '+$name+'</b><br><p>Vous voulez suspendre cet utilisateur?</p>');
                		$("#banned .modal-footer").html(' <button type="button" class="btn btn-default" data-dismiss="modal">Non</button> <button id="bannedUser" type="button" class="btn btn-danger" data-loading-text="traitement..." onclick = "do_banned('+$data+')" >OUI</button>');
            }


			function do_banned($id,$name)
			{
				 var $data = "'"+$id+"','"+$name+"'";
				var btn = $("#bannedUser");
			    btn.button('loading');
				$.ajax({
					  async: false, 	
					  type: 'POST',
					  url: '<?=site_url()?>users/bannedUser',
					  data: {id: $id},
					  success: function(data){
							
							btn.button('reset');
							$('.status_'+$id+' span').removeClass('label-success').addClass('label-danger');
							$('.status_'+$id+' .label-danger').html('suspendu');
							$('.bannedUser_'+$id).html('<i class="fa fa-check-circle"></i>');
							$('.bannedUser_'+$id).attr('onclick','unbanUser('+$data+')');
							$("#banned .modal-body p").html('<span class="text-red">Ce compte a été suspendu.</span>');
							$("#banned .modal-footer").html(' <button type="button" class="btn btn-default" data-dismiss="modal">Fermer</button> ');
						  },
					  dataType: 'json'
					});
			}

			function unbanUser($id,$name)
			{
				var $data = "'"+$id+"','"+$name+"'";
				$('#unban').modal({
          		  keyboard: false
          		});
				$("#unban .modal-title").html('Activer cet utilisateur');
        		$("#unban .modal-body").html('<b>Compte: '+$name+'</b><br><p>Vous voulez activer cet utilisateur?</p>');
        		$("#unban .modal-footer").html(' <button type="button" class="btn btn-default" data-dismiss="modal">Non</button> <button id="unbanUser" type="button" class="btn btn-success" data-loading-text="traitement..." onclick = "do_unban('+$data+')" >OUI</button>');
			}

			function do_unban($id,$name)
			{
				var $data = "'"+$id+"','"+$name+"'";
				var btn = $("#unbanUser");
			    btn.button('loading');
				$.ajax({
					  async: false, 	
					  type: 'POST',
					  url: '<?=site_url()?>users/unbanUser',
					  data: {id: $id},
					  success: function(data){
							
							btn.button('reset');
							$('.status_'+$id+' span').removeClass('label-danger').addClass('label-success');
							$('.status_'+$id+' .label-success').html('activé');
							$('.bannedUser_'+$id).html('<i class="fa fa-minus-circle"></i>');
							$('.bannedUser_'+$id).attr('onclick','bannedUser('+$data+')');
							$("#unban .modal-body p").html('<span class="text-green">Ce compte a été activé.</span>');
							$("#unban .modal-footer").html(' <button type="button" class="btn btn-default" data-dismiss="modal">Fermer</button> ');
						  },
					  dataType: 'json'
					});
			}


	          function deleteUser($id,$name){
	              var $data = "'"+$id+"','"+$name+"'";
	            
	            	$('#deleteUser').modal({
	            		  keyboard: false
	            		});
	                		$("#deleteUser .modal-title").html('supprimer compte');
	                		$("#deleteUser .modal-body").html('<b>Compte: '+$name+'</b><br><p>Vous voulez supprimer ce compte ?</p>');
	                		$("#deleteUser .modal-footer").html(' <button type="button" class="btn btn-default" data-dismiss="modal">Non</button> <button id="deleteUserBtn" type="button" class="btn btn-danger" data-loading-text="traitement..." onclick = "do_delete('+$data+')" >OUI</button>');
	            }


				function do_delete($id,$name)
				{
					var $data = "'"+$id+"','"+$name+"'";
					var btn = $("#deleteUserBtn");
				    btn.button('loading');
					$.ajax({
						  async: false, 	
						  type: 'POST',
						  url: '<?=site_url()?>users/deleteUser',
						  data: {id: $id},
						  success: function(data){
								
								btn.button('reset');
								$('#user_'+$id).remove();
								$("#deleteUser .modal-body p").html('<span class="text-red">Ce compte a été effacé.</span>');
								$("#deleteUser .modal-footer").html(' <button type="button" class="btn btn-default" data-dismiss="modal">Fermer</button> ');
							  },
						  dataType: 'json'
						});
				}

			    function resetPass($id,$name){
		              var $data = "'"+$id+"','"+$name+"'";
		            
		            	$('#resetPass').modal({
		            		  keyboard: false,
		            		  backdrop:"static"
		            		});
		                		$("#resetPass .modal-title").html('Mot de passe');
		                		$("#resetPass .modal-body").html('<b>Compte: '+$name+'</b><br><p>Vous voulez réinitialiser le mot de passe ?</p>');
		                		$("#resetPass .modal-footer").html(' <button type="button" class="btn btn-default" data-dismiss="modal">Non</button> <button id="resetPassBtn" type="button" class="btn btn-danger" data-loading-text="traitement..." onclick = "do_reset('+$data+')" >OUI</button>');
		            }
			    function do_reset($id,$name)
				{
					var $data = "'"+$id+"','"+$name+"'";
					var btn = $("#resetPassBtn");
				    btn.button('loading');
					$.ajax({
						  async: false, 	
						  type: 'POST',
						  url: '<?=site_url()?>users/sendVerifyCode',
						  data: {id: $id},
						  success: function(data){
								btn.button('reset');
								if(data == true){
								$("#resetPass .modal-body p").html('<span class="text-success">Le code de vérification pour '+$name+' a été envoyé par email.</span>');
								$("#resetPass .modal-footer").html(' <button type="button" class="btn btn-default" onclick="modalDismiss()" >Fermer</button> ');
								}else{
								$("#resetPass .modal-body p").html('<span class="text-danger">Il y a une erreur.</span>');
								$("#resetPass .modal-footer").html(' <button type="button" class="btn btn-default" data-dismiss="modal" >Fermer</button> ');
									}
							
							  },
						  dataType: 'json'
						});
				}

			    function modalDismiss(){
					$('#resetPass').modal().hide(function(){
							location.reload();
						});		  
					}   
        </script>